package com.hg.oa.module.calendar.layer;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.transition.Slide;
import android.transition.Transition;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;

import com.hg.oa.R;
import com.hg.oa.module.calendar.presenter.CalendarPressenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 日报填写或者请假申请
 * Created by fengxiang on 2016/9/9.
 */
public class DayInputActivity extends AppCompatActivity {

    public static int TYPE_REPORT = 1;
    public static int TYPE_LEVEL = 2;
    String tag = "DayInputActivity";
    Unbinder unbinder;

    @BindView(R.id.spinner)
    Spinner spinner;

    @BindView(R.id.leftBtn1)
    ImageView leftBtn1;

    CalendarPressenter pressenter;

    int typeFromHomeMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_day_input);
        unbinder = ButterKnife.bind(this);
        typeFromHomeMenu = getIntent().getIntExtra("type", TYPE_REPORT);
        pressenter = new CalendarPressenter(this);
        setupWindowAnimations();
        String[] strs = new String[]{"填写日报", "请假申请"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                this, android.R.layout.simple_spinner_dropdown_item
                , strs
        );

        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                Log.e(tag, "pos-->" + position);
                if (position == 0) {
                    pressenter.applyDayReport(R.id.container_day, getSupportFragmentManager().beginTransaction());
                } else if (position == 1) {
                    pressenter.applyLevelReport(R.id.container_day, getSupportFragmentManager().beginTransaction());
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        if (typeFromHomeMenu == TYPE_REPORT) {
            spinner.setSelection(0);
        } else if (typeFromHomeMenu == TYPE_LEVEL) {
            spinner.setSelection(1);
        }
    }

    @OnClick(R.id.leftBtn1)
    void back() {
        finishAfterTransition();
    }

    private void setupWindowAnimations() {
        Transition transition = buildEnterTransition();
        getWindow().setEnterTransition(transition);
    }

    private Transition buildEnterTransition() {
        //explode 动画方式 从上往下掉的感觉
//        Explode enterTransition = new Explode();
//        enterTransition.setDuration(getResources().getInteger(R.integer.anim_duration_long));
//        return enterTransition;

        //侧边滑出
        Slide enterTransition = new Slide();
        enterTransition.setDuration(getResources().getInteger(R.integer.anim_duration_long));
        enterTransition.setSlideEdge(Gravity.RIGHT);
        return enterTransition;
    }

}
